var arr = [1, 2, 3]


console.log(Array.isArray(arr));

console.log(new Array(2));
console.log(Array.of(2));

var set = new Set([1, 2])
console.log(set);
console.log(Array.from(set));

console.log(arr.pop());
console.log(arr);
console.log(arr.shift());
console.log(arr);
arr.push(3)
console.log(arr);
arr.unshift(1)
console.log(arr);

//增
arr.splice(2, 0, 2.5);
console.log(arr);
//删
arr.splice(2, 1)
console.log(arr);
//改
arr.splice(1, 1, 3)
console.log(arr);

arr.reverse()
console.log(arr);

var arr = [6, 3, 7, 4, 5, 8, 3]
/* arr.sort((a,b)=>{
    return a-b
})
console.log(arr);
arr.sort((a,b)=>{
    return b-a
})
console.log(arr); */

//数组初始化
console.log(new Array(2).fill(1));

/* arr.fill(1)
console.log(arr); */

console.log(arr.slice(1, 3));

console.log(arr.toString());
var str = arr.join(',')
var arrStr = str.split(',')
var arr = arrStr.map(item => {
    return parseInt(item)
})
console.log(arr);

var arr1 = [1, 2]
console.log(arr.concat(arr1));

console.log(arr.indexOf(3));
console.log(arr.lastIndexOf(3));
console.log(arr.includes(3));

arr.forEach((item, index) => {
    console.log(item, index);
})

console.log(arr.some(item => {
    console.log(item);
    return item > 7
}));

console.log(arr.every(item => {
    return item > 3
}));

console.log(arr.filter(item => {
    return item > 4
}));

var arr = [1, [2], [[[3]]]]
console.log(arr.flat(1));
console.log(arr.flat(2));
console.log(arr.flat(Infinity));

var arr = [1, 2, 3]
arr.reduce((pre, item, index) => {
    console.log(pre, item, index);
    return ''
}, '')
//累加器
console.log(arr.reduce((pre, item, index) => {
    return pre + item
}, 0));